package com.pb.wkflow.api.controller;

import com.pb.infra.oth.entity.common.Result;
import com.pb.wkflow.api.controller.request.ProcDefFieldRequest;
import com.pb.wkflow.api.service.WfSysProcDefFieldService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 流程定义字段配置
 * @author 苗益辉
 * @date 2023/4/17 15:56
 */
@Slf4j
@RestController
@RequestMapping("v1/workflow/field")
public class ProcDefFieldApi {

    @Autowired
    private WfSysProcDefFieldService wfSysProcDefFieldService;

    /**
     * 新增或修改流程定义字段配置
     * @param request request
     * @return Result
     */
    @PostMapping("/addOrUpdate")
    public Result addOrUpdate(@RequestBody ProcDefFieldRequest request) {
        log.info("---------- 新增或修改流程定义字段配置 ---------- {}", request);
        wfSysProcDefFieldService.addOrUpdate(request);
        return Result.OK_EMPTY;
    }

    /**
     * 查询流程定义字段配置
     * @param request request
     * @return Result
     */
    @PostMapping("/get")
    public Result findByKey(@RequestBody ProcDefFieldRequest request) {
        log.info("---------- 查询流程定义字段配置 ---------- {}", request);
        return Result.ok(wfSysProcDefFieldService.findByKey(request));
    }
}
